﻿@using Framework.Util.Helpers
@model IEnumerable<Project.Domain.Entities.Match> 

<script type="text/javascript">
    //Custom Form
    $('.custom_chk').jqTransCheckBox();
    $('.custom_rd').jqTransRadio();
    $('.custom_select').jqTransSelect();
    var result = "@ViewBag.result";
    var page = "@ViewBag.page";
</script>
            
<div class="content_table">
    <table cellspacing="0" cellpadding="0" border="0" width="100%">
        <tr>
            <th class="th_no_cursor" width="40">No.</th>
            <th class="th_no_cursor" width="31">
                <input type="checkbox" class="custom_chk" id="selectAllItems" onclick="selectAllItems(@ViewBag.result)" />
            </th>
            <th class="th_left" onclick="sort('title')">
                <div id="title" class="sort icon_no_sort">HomeTeam</div>
            </th>
            <th class="th_left" onclick="sort('title')">
                <div id="title" class="sort icon_no_sort">AwayTeam</div>
            </th>
            <th class="th_left" onclick="sort('title')">
                <div id="title" class="sort icon_no_sort">League</div>
            </th>                       
            <th class="th_left" onclick="sort('title')">
                <div id="title" class="sort icon_no_sort">DatePlay</div>
            </th>
            <th class="th_left" onclick="sort('title')">
                <div id="title" class="sort icon_no_sort">TimePlay</div>
            </th>
            <th class="th_left" onclick="sort('title')">
                <div id="title" class="sort icon_no_sort">EndTime</div>
            </th>
            <th class="th_left" onclick="sort('title')">
                <div id="title" class="sort icon_no_sort">Score</div>
            </th> 
            <th width="70" onclick="sort('status')">
                <div id="status" class="sort icon_no_sort">Allow</div>
            </th>
            <th width="70" onclick="sort('status')">
                <div id="status" class="sort icon_no_sort">Status</div>
            </th>
            <th class="th_last" width="100" onclick="sort('created')">
                <div id="created" class="sort icon_sort_asc">Created</div>
            </th>
        </tr>
        @{
            var start = Convert.ToInt32(ViewBag.start);
            if (Convert.ToInt32(ViewBag.result) > 0)
            {
                var i = 0;
                var count = 0;
                foreach (var match in Model)
                {
                    count = count + 1;
                    var classCss = "item_row" + i.ToString();
                    var idItem = "item" + i.ToString();
                    var loadStatusID = "loadStatusID_" + match.MatchId;
                    <tr class="@classCss @(i % 2 == 0 ? Html.Raw("row1") : Html.Raw("row2"))">					
                        <td class="td_center">@(count + start)</td>
                        <td class="td_no_padd">
                            <input type="checkbox" class="custom_chk" id="@idItem" onclick="     selectItem(@i) " value="@match.MatchId" />
                        </td>
                        <td class="th_left">
                            <a href="@Url.Action("Modify", "Match", new { id = match.MatchId })">@match.HomeTeam.TeamName</a>
                        </td>
                        <td class="th_left">
                            <a href="@Url.Action("Modify", "Match", new { id = match.MatchId })">@match.AwayTeam.TeamName</a>
                        </td>
                        <td class="th_left">
                            <a href="@Url.Action("Modify", "Match", new { id = match.MatchId })">@match.League.NameLeague</a>
                        </td> 
                        
                        <td class="th_left">
                            <a href="@Url.Action("Modify", "Match", new { id = match.MatchId })">@string.Format("{0:dd-MM-yyyy}", match.CreatedTime)</a>
                        </td>
                        
                        <td class="th_left">
                            <a href="@Url.Action("Modify", "Match", new { id = match.MatchId })">@match.TimePlay</a>
                        </td>
                        
                        <td class="th_left">
                            <a href="@Url.Action("Modify", "Match", new { id = match.MatchId })">@string.Format("{0:dd-MM-yyyy}", match.EndTime)</a>
                        </td>
                        
                        <td class="th_left">
                            <a href="javascript:void(0)">@Html.Slip(match.HomeScore.ToString()) : @Html.Slip(match.AwayScore.ToString())</a>
                        </td>

                        <td class="td_center" id="@loadStatusID">
                            @switch (match.IsPlay)
                            {
                                case 0:
                                    {
                                        if (match.Status)
                                        {
                                            <a href="javascript:void(0)" onclick="updateStatus(@match.MatchId, @Convert.ToInt32(match.Status), 'Match')">
                                                <img alt="Checked item" src="@Url.Content("~/Areas/Content/images/icons/check_16x16.png")"  title="unLock"/>
                                            </a>
                                        }
                                        else
                                        {
                                            <a href="javascript:void(0)" onclick="updateStatus(@match.MatchId, @Convert.ToInt32(match.Status), 'Match')">
                                                <img alt="Checked item" src="@Url.Content("~/Areas/Content/images/icons/uncheck_16x16.png")" title="Locked"/>
                                            </a>
                                        }
                                        break;
                                    }
                                case 1:
                                    {
                                        <a href="javascript:void(0)" title="Match closed">
                                            <img alt="Checked item" src="@Url.Content("~/Areas/Content/images/icons/uncheck_16x16.png")" title="Locked! Match closed"/>
                                        </a>
                                        break;
                                    }
                                default:
                                    {
                                        if (match.Status)
                                        {
                                            <a href="javascript:void(0)" title="Match InPlay">
                                                <img alt="Checked item" src="@Url.Content("~/Areas/Content/images/icons/check_16x16.png")"  title="Action not allow! Match InPlay"/>
                                            </a>
                                        }
                                        else
                                        {
                                            <a href="javascript:void(0)" title="Match InPlay">
                                                <img alt="Checked item" src="@Url.Content("~/Areas/Content/images/icons/uncheck_16x16.png")" title="Action not allow! Match InPlay"/>
                                            </a>
                                        }
                                        break;
                                    }
                            }                                                                                                                                                
                        </td>
                        
                        <td class="td_center" id="@loadStatusID">
                            <a href="javascript:void(0)">
                                @switch (match.IsPlay)
                                {
                                    case 0:
                                        <span>New</span>
                                        break;
                                    case 2:
                                        <span>InPlay</span>
                                        break;
                                    default:
                                        <span>EndPlay</span>
                                        break;
                                }                                                                                              
                            </a>
                        </td>

                        <td class="th_last td_center">
                            @string.Format("{0:dd-MM-yyyy}", match.CreatedTime)
                        </td>
                    </tr>
                                i += 1;
                }
            }
            else
            {
                <tr class="row1">
                    <td class="th_last td_center" colspan="50" style="font-size: 20px; padding: 50px 0">No data</td>
                </tr>
            }
        }
    </table>
</div>
<div class="footer_table">
    <div class="item_per_page">Items per page:</div>            
    <div id="phantrang_clip" style="width: 200px; float: left;">
        <div style="float:left;margin-bottom: 5px;">
            @Html.Raw((Html.Pager((MvcContrib.Pagination.IPagination)Model).Format("").SingleFormat("").First("First").Last("Last").Next("").Previous("")).ToString())
        </div>
        <div class="ClearAll"></div>
    </div>    
</div>